Fix VMobject.add_points_as_corners()
to return self
and safely handle empty points
parameter
#4091
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #4090
In the earlier PR #3765, I optimized
VMobject.add_points_as_corners()
to allocate space forVMobject.points
only once, instead of calling N times in a for loop theadd_line_to()
method which allocated space N times, one for each point. This is really helpful for drawing and animating multipleParametricFunction
s and/orImplicitFunction
s, which tend to require the computation of a lot of points which are then interpolated smoothly.However, I missed the edge case in which the
points
parameter contains 0 points, which caused the crash described in #4090. It is possible that theImplicitFunction
algorithm for finding a sample of points belonging to the curve returns a single point for one or more branches (calledcurves
) of the full implicit curve. In that case, the following three lines inImplicitFunction.generate_points()
will fail because of that mistake:In this PR, I fix this behavior by returning earlier from
VMobject.add_points_as_corners()
ifpoints
is empty, in a similar way to what the original method already implicitly did (no points = no iterations inside the original for loop).Plus, instead of returning the passed
points
(which is useless, because you already had the points beforehand), I made this method returnself
(which is consistent with many other methods and allows us to chain this method with other subsequent calls).Reviewer Checklist